package com.saibo.spider.gather.service;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.TimerTask;

import com.saibo.spider.commons.ConnectServer;
import com.saibo.spider.utils.StringUtil;

public class SinaService extends TimerTask {

	String macaddr;

	public SinaService(String macaddr) {
		this.macaddr = macaddr;
	}

	@Override
	public void run() {
		Map<String, Object> mso = new HashMap<String, Object>();
		mso.put("macaddr", macaddr);
		mso.put("taskId", "1");
		String json = ConnectServer.sendPostRequest("http://192.168.1.177:8081/services/schedule/obtainentryinfo",
				StringUtil.mapToJson(mso));
		if(StringUtil.isNullOrEmpty(json))
			return;
		Map<String, Object> missionMap = StringUtil.jsonToMap(json);
		String actionname = missionMap.get("actionname").toString();
		String url = missionMap.get("url").toString();
		Class<?> class1 = null;
		try {
			class1 = Class.forName("com.saibo.spider.gather."+actionname);
			Method method = class1.getMethod("startM", String.class);
			method.invoke(class1.newInstance(), url);
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}

}
